package com.xywy.beautyand.fragment;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xywy.beautyand.R;
import com.xywy.beautyand.base.BaseFragment;
import com.xywy.beautyand.custom.VerticalPager;

public class CountFragment extends BaseFragment {
	private VerticalPager vertyPager1;
	int[] img = { R.drawable.img1, R.drawable.img2, R.drawable.img3,
			R.drawable.img4, R.drawable.img5, R.drawable.img6, R.drawable.img7 };
	private RelativeLayout rel1;
	private TextView text1;
	private RelativeLayout rel2;
	private TextView text2;
	private RelativeLayout rel3;
	private TextView text3;
	private RelativeLayout rel4;
	private TextView text4;
	private RelativeLayout rel5;
	private TextView text5;
	private RelativeLayout rel6;
	private TextView text6;
	private RelativeLayout rel7;
	private TextView text7;


	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.frag_count, null);
		initView(view);
		initListener();
		initdata();
		return view;

	}

	private void initView(View view) {
		// TextView text=(TextView) view.findViewById(R.id.text);
		// text.setText("统计");

		vertyPager1 = (VerticalPager) view.findViewById(R.id.vertyPager1);

		rel1 = (RelativeLayout) view.findViewById(R.id.rel1);
		text1 = (TextView) view.findViewById(R.id.text1);

		rel2 = (RelativeLayout) view.findViewById(R.id.rel2);
		text2 = (TextView) view.findViewById(R.id.text2);

		rel3 = (RelativeLayout) view.findViewById(R.id.rel3);
		text3 = (TextView) view.findViewById(R.id.text3);

		rel4 = (RelativeLayout) view.findViewById(R.id.rel4);
		text4 = (TextView) view.findViewById(R.id.text4);

		rel5 = (RelativeLayout) view.findViewById(R.id.rel5);
		text5 = (TextView) view.findViewById(R.id.text5);

		rel6 = (RelativeLayout) view.findViewById(R.id.rel6);
		text6 = (TextView) view.findViewById(R.id.text6);

		rel7 = (RelativeLayout) view.findViewById(R.id.rel7);
		text7 = (TextView) view.findViewById(R.id.text7);

		vertyPager1.removeAllViews();
		addPagerView(img[0], rel1, text1, "2014年12月25日");
		addPagerView(img[1], rel2, text2, "23445");
		addPagerView(img[2], rel3, text3, "2014年12月27日");
		addPagerView(img[3], rel4, text4, "234");
		addPagerView(img[4], rel5, text5, "212");
		addPagerView(img[5], rel6, text6, "235");
		addPagerView(img[6], rel7, text7, "234452");
		
		
		
		
		
		

	}

	private void initListener() {

	}

	private void initdata() {

	}

	private void addPagerView(final int img, RelativeLayout rel, TextView tv,
			String text) {

		BitmapDrawable bd = new BitmapDrawable(decodeResource(img));
		rel.setBackgroundDrawable(bd);
		tv.setText(text);
		vertyPager1.addView(rel);

	}

	private Bitmap decodeResource(int resouce) {
		try {
			// decode image size
			BitmapFactory.Options o = new BitmapFactory.Options();
			o.inJustDecodeBounds = true;
			BitmapFactory.decodeResource(getResources(), resouce, o);
			final int REQUIRED_SIZE = 400;
			int width_tmp = o.outWidth, height_tmp = o.outHeight;
			int scale = 1;
			while (true) {
				if (width_tmp / 2 < REQUIRED_SIZE
						|| height_tmp / 2 < REQUIRED_SIZE)
					break;
				width_tmp /= 2;
				height_tmp /= 2;
				scale *= 2;
			}

			BitmapFactory.Options o2 = new BitmapFactory.Options();
			o2.inSampleSize = scale;
			return BitmapFactory.decodeResource(getResources(), resouce, o2);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
